package com.sharemob.tinchat.lib;

import java.lang.Thread.UncaughtExceptionHandler;

import android.app.Application;
import android.widget.Toast;

import com.sharemob.tinchat.thirdparty.weixin.WXConstant;
import com.tencent.mm.sdk.openapi.WXAPIFactory;

/**
 * 
 * 
 * <一句话功能简述>
 *
 * @author lihangjie
 * version [版本号,2015-9-11 下午3:39:22]
 * @see    [相关类/方法]
 * @since  [产品/模块版本]
 *
 */
public class MyApplication extends Application {

		
	 private UncaughtExceptionHandler defaultExceptionHandler;
	    public MyApplication(){
	    	System.out.println("启动Application");
	    	WXConstant.context=this;
	    	
	    }
	    
	    public void onCreate()
	    {
	        super.onCreate();
	        
	        WXConstant.api = WXAPIFactory.createWXAPI(this, WXConstant.AppID, false);
	       
	        
			if( !WXConstant.api.isWXAppInstalled()){
	            Toast.makeText(WXConstant.context, "请先安装微信应用", Toast.LENGTH_SHORT).show();
	        }else{
	        	Toast.makeText(WXConstant.context, "已安装微信应用", Toast.LENGTH_SHORT).show();
	        }
	        if( !WXConstant.api.isWXAppSupportAPI() ){
	            Toast.makeText(WXConstant.context, "请先更新微信应用", Toast.LENGTH_SHORT).show();
	        }
	        
	        //捕获应用异常
	        catchUncaughtExceptionHandler();
	   	 	//对更新服务检测更新版本
	   	 	UpdateService();
	        
	    }

	    /**
	     * 检测更新服务组件
	     */
	    private void UpdateService(){
	    	
	    }

	    
	    public void onTerminate()
	    {
	        super.onTerminate();
	    }

	    /**
	     * 记录未捕捉异常
	     * @exception throws
	     */
	    private void catchUncaughtExceptionHandler() {
	        defaultExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
	        Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
	            @Override
	            public void uncaughtException(Thread thread, Throwable ex) {
	                defaultExceptionHandler.uncaughtException(thread, ex);
	            }
	        });
	    }
}
